home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / tclib.zip / FASTWR.C next >
Text File  |  1987-06-03  |  4KB  |  97 lines

  1. /*;fastwrite.c     -    a modification of FastWrite.PAS
  2.   ;                 to run under Microsoft C using the MASM Assembler
  3.   ;                 Writes directly to the screen buffer
  4.   ;
  5.   ;                 modified yet again to run under Turbo C
  6.   ;                 by Jim Texter [71426,417]
  7.   ;                 compile using -B compiler switch
  8.   ;
  9.   ;   This routine is based on the FastWrite routine submitted
  10.   ;   to the Borland SIG on CompuServe. It has been tested for
  11.   ;   use with programs written under the Turbo C Compiler,
  12.   ;   version 1.0. I have tested it under the large and hughe
  13.   ;   memory models only.
  14.   ;   In calling the routine from a C program, the value for
  15.   ;   the string 'st' can be supplied by passing a pointer to
  16.   ;   a string or, as is convenient with C, a string literal
  17.   ;   itself (the program will take the address of the 0th element
  18.   ;   of the string).
  19.   ;
  20.   ;   Acknowledgements:
  21.   ;   Brian Foley submitted the Turbo Pascal inline code version
  22.   ;   of this routine to the Borland SIG on CompuServe. David B.
  23.   ;   Rein helped to convert the code, and some final modifications
  24.   ;   were done by Michael D. Most.
  25.   ;
  26.   ;   Questions may be answered by contacting Brian Foley on
  27.   ;   CompuServe [76317,3247], or Mike Most [70446,1244].
  28.   ;
  29.   ;
  30.   ;**********************************************************
  31.   ;*                                                        *
  32.   ;*            usage:    fastwrite(st,row,col,attr)            *
  33.   ;*                     char *st;                            *
  34.   ;*                     int row, col, attr;                *
  35.   ;*                                                        *
  36.   ;**********************************************************/
  37.  
  38.  
  39. fastwrite (char *st, int row, int col, int attr)
  40. {
  41.             asm  mov      bx,si            /*save SI in BX      */
  42.             asm  mov      ax,40h           /*get video mode                */
  43.             asm  mov      es,ax
  44.             asm  mov      dl,es:[49h]       /*DL=Video mode, stored by BIOS */
  45.             asm  mov      di,row           /*DI=Row                        */
  46.             asm  dec      di               /*make row 0-24 instead of 1-25 */
  47.             asm  mov      cl,4               /*CL=4, CH=0                    */
  48.             asm  shl      di,cl            /*DI=Row*32                       */
  49.             asm  mov      ax,di            /*store in AX                   */
  50.             asm  shl      di,1               /*DI=Row*32                       */
  51.             asm  shl      di,1               /*DI=Row*64                       */
  52.             asm  add      di,ax            /*di=row*80                       */
  53.             asm  add      di,col           /*Add (Col +1) to di            */
  54.             asm  dec      di               /*DI=(Row*80) + Column           */
  55.             asm  shl      di,1               /*account for attribute byte    */
  56.             asm  lds      si,st            /*DS:SI points to String     */
  57.             asm  mov      ah,attr           /*AH = attribute                */
  58.             asm  cmp      dl,7               /*Mono??                        */
  59.             asm  je       mono
  60.             asm  mov      dx,0b800h        /*base of video buffer           */
  61.             asm  mov      es,dx            /*ES = segment for color memory */
  62.             asm  mov      dx,03dah           /*6845 port address               */
  63. getnext:    asm  lodsb                       /*load next char into al        */
  64.             asm  or       al,al            /*test for null character       */
  65.             asm  jz       exit               /*exit if it's a null           */
  66.             asm  mov      cx,ax            /*store video word in CX        */
  67.             asm  cli                       /*no interrupts                   */
  68. waitnoh:    asm  in       al,dx            /*get 6845 status               */
  69.             asm  test      al,8               /*Vertical retrace?               */
  70.             asm  jnz      store            /*if so, go                       */
  71.             asm  rcr      al,1               /*else, wait for end of           */
  72.             asm  jc       waitnoh           /*horizontal retrace            */
  73. waith:        asm  in       al,dx            /*get 6845 status again           */
  74.             asm  rcr      al,1               /*wait for horizontal           */
  75.             asm  jnc       waith           /*retrace                       */
  76. store:        asm  mov       ax,cx           /*move word back to AX..        */
  77.             asm  stosw                       /*and then to screen            */
  78.             asm  sti                       /*allow interrupts               */
  79.             asm  jmp      short getnext    /*get next character            */
  80. mono:        asm  mov      dx,0b000h
  81.             asm  mov      es,dx            /*ES = segment for mono memory  */
  82. next:        asm  lodsb                       /*Load next char into AL        */
  83.             asm  or       al,al            /*Test for null char            */
  84.             asm  jz       exit               /*Exit if it's a null           */
  85.             asm  stosw                       /*Move video word into place    */
  86.             asm  jmp      short next       /*get next character            */
  87. exit:        asm  mov      si,bx            /*restore SI from BX            */
  88.  
  89.  
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.